package com.kc.service.impl;

import com.kc.bean.AccountRelam;
import com.kc.mapper.AccountRelamMapper;
import com.kc.service.ShiroService;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service("shiroService")
public class ShiroServiceImpl implements ShiroService {

    @Resource
    private AccountRelamMapper accountRelamMapper;

    @Override
    public Map<String, String> LoadAccountUrl() {

        //把数据库中的url以及所需权限提取出来
        List<AccountRelam> accountRelams = accountRelamMapper.selectList(null);

        Map<String, String> map = new LinkedHashMap<>();

        if (accountRelams.size() > 0) {
            for (AccountRelam accountRelam : accountRelams){
                map.put(accountRelam.getUrl(),accountRelam.getRelam());
            }
        }
        map.put("/getphonecode","anon");
        map.put("/login","anon");
        map.put("/register","anon");
        //测试专用url
        map.put("/test/**","anon");
        map.put("/upload-images/**","anon");
        map.put("/**","token");

        return map;
    }


    /**
     * 只有当我们需要删除某一个用户的某一个权限的时候我们才需要重新刷新。接口暂时无用
     *
     * @param shiroFilterFactoryBean
     */
    @Override
    public void updatePermission(ShiroFilterFactoryBean shiroFilterFactoryBean) {

    }
}
